package com.runa.rccprotocol.dto.hanyang;

import com.runa.protocol.util.ByteUtil;

/**
 * 2024/11/28 13:19
 * zhangYB
 */
public class HyMeterRequestData {

    public static void main(String[] args) {
        HyMeterRequestData requestData = new HyMeterRequestData();
        byte[] bytes = requestData.readHyMeter("12345678");
        System.out.println(ByteUtil.byteToHexString(bytes));
    }

    public byte[] readHyMeter(String serial) {
        byte[] data = new byte[100];
        int i = 0;
        data[i++] = (byte)0xFE;
        data[i++] = (byte)0xFE;
        data[i++] = (byte)0xFE;
        int begin = i;
        data[i++] = (byte)0x68;
        data[i++] = (byte)0x20;
        while (serial.length() < 8) {
            serial = "0" + serial;
        }
        byte[] bytes = ByteUtil.hexStringToByteFlip(serial);
        for (byte b : bytes) {
            data[i++] = b;
        }
        data[i++] = (byte)0x00;
        data[i++] = (byte)0x35;
        data[i++] = (byte)0x79;
        data[i++] = (byte)0x01;
        data[i++] = (byte)0x03;
        data[i++] = (byte)0x1F;
        data[i++] = (byte)0x90;
        data[i++] = (byte)0x12;
        data[i++] = ByteUtil.sum(data, begin, i - begin);
        data[i++] = (byte)0x16;

        byte[] r = new byte[i];
        System.arraycopy(data, 0, r, 0, r.length);
        return r;
    }



}
